/*
 * Pwm.c
 *
 *  Created on: 2016-4-23
 *      Author: Billli
 */

#include "Pwm.h"

void OpenPwm(void ){
	BUS_WR(PWM_CS,EN_OFFSET,1);
}
void ClosePwm(void ){
	BUS_WR(PWM_CS,EN_OFFSET,0);
}
void SetPwmWave(double freq,double duty){
	alt_u32 CCR0;
	alt_u32 CCR1;
	if(freq>50000000)
		return ;
	if(freq<0)
		return ;
	if(duty>1)
		return ;
	if(duty<0)
		return ;
	CCR0= (alt_u32 )1.0*CPU_FREQ/freq-1;
	CCR1= (alt_u32 ) 1.0*CCR0*duty;
	BUS_WR(PWM_CS,CCR0_OFFSET,CCR0);
	BUS_WR(PWM_CS,CCR1_OFFSET,CCR1);
}



